﻿/*************************************************************************************
 * 文 件 名:   UI_RoamCamCtrl
 * 
 * 描    述:   RoamingCam的UI测试脚本
 * 
 * 版    本：  V1.0
 * 创 建 者：  谭潇杰、京产肠饭
 * 创建时间：  2022/1/28
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using UnityEngine;
using UnityEngine.UI;
using QFramework;

namespace HKTools
{
    public class Test_UIRoamCamCtrl : HK_RoamingCamController
    {
        IHK_RoamingCamSystem roamingCamSystem;

        [Header("底部三个开关：")]
        [SerializeField] Toggle roam_Toggle;
        [SerializeField] Toggle birdView_Toggle;
        [SerializeField] Toggle threeD_Toggle;

        void Awake()
        {
            roamingCamSystem = this.GetSystem<IHK_RoamingCamSystem>();
        }

        void Start()
        {
            // 点击漫游Toggle
            roam_Toggle.onValueChanged.AddListener(isOn =>
            {
                if (!isOn)
                    return;

                this.SendCommand(new CMD_ChangeViewMode(ViewMode.RoamView));
            });

            //点击鸟瞰Toggle
            birdView_Toggle.onValueChanged.AddListener(isOn =>
            {
                if (!isOn)
                    return;

                this.SendCommand(new CMD_ChangeViewMode(ViewMode.BirdView));
            });

            //点击三维Toggle
            threeD_Toggle.onValueChanged.AddListener(isOn =>
            {
                if (!isOn)
                    return;

                this.SendCommand(new CMD_ChangeViewMode(ViewMode.ThreeDView));
            });

            roamingCamSystem.IsCanRotCam.Register(value =>
            {
                roam_Toggle.interactable = value;
                birdView_Toggle.interactable = value;
                threeD_Toggle.interactable = value;
            }).UnRegisterWhenGameObjectDestroyed(gameObject);

            roamingCamSystem.CurViewMode.Register(value =>
            {
                switch (value)
                {
                    case ViewMode.BirdView:
                        birdView_Toggle.isOn = true;
                        break;
                    case ViewMode.ThreeDView:
                        threeD_Toggle.isOn = true;
                        break;
                    case ViewMode.RoamView:
                        roam_Toggle.isOn = true;
                        break;
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
        }
    }
}